options compress=YES;
libname manasi ''; 

* PREP DATA FOR RD ;
data manasi.analysis04_entryrd;
	set manasi.kids_cdryrs_mergecdr_clean (rename=(n_firstage=n_firstage_exact));
	
* KEEP ONLY FY2004/05 KIDS WHO ARE NOT ON HOLD AND HAVE CURRENT MDD;
	if (fy=2004| fy=2005) & n_cdr_hold=0 & cdr_mddate>=200310;
	drop cs_toa mft n_diag2_: ;

* Create one categorical variable for diagnosis;
	if n_diag1_infec=1 			then n_diag1cat=1 ;
	else if n_diag1_neo=1 		then n_diag1cat=2 ;
	else if n_diag1_endo=1		then n_diag1cat=3 ;
	else if n_diag1_blood=1		then n_diag1cat=4 ;
	else if n_diag1_mental=1	then n_diag1cat=5 ;
	else if n_diag1_nerv=1		then n_diag1cat=6 ;
	else if n_diag1_sense=1		then n_diag1cat=7 ;
	else if n_diag1_circ=1		then n_diag1cat=8 ;
	else if n_diag1_resp=1		then n_diag1cat=9 ;
	else if n_diag1_dig=1		then n_diag1cat=10 ;
	else if n_diag1_gu=1		then n_diag1cat=11 ;
	else if n_diag1_preg=1		then n_diag1cat=12 ;
	else if n_diag1_skin=1		then n_diag1cat=13 ;
	else if n_diag1_musc=1		then n_diag1cat=14 ;
	else if n_diag1_cong=1		then n_diag1cat=15 ;
	else if n_diag1_nat=1		then n_diag1cat=16 ;
	else if n_diag1_ill=1		then n_diag1cat=17 ;
	else if n_diag1_inj=1		then n_diag1cat=18 ;

* RENAME FIRST AGE VARIABLE;
	if n_firstage_exact>=0 & n_firstage_exact<1 then n_firstage=0;
		else if n_firstage_exact>=1 & n_firstage_exact<2 then n_firstage=1;
		else if n_firstage_exact>=2 & n_firstage_exact<3 then n_firstage=2;
		else if n_firstage_exact>=3 & n_firstage_exact<4 then n_firstage=3;
		else if n_firstage_exact>=4 & n_firstage_exact<5 then n_firstage=4;
		else if n_firstage_exact>=5 & n_firstage_exact<6 then n_firstage=5;
		else if n_firstage_exact>=6 & n_firstage_exact<7 then n_firstage=6;
		else if n_firstage_exact>=7 & n_firstage_exact<8 then n_firstage=7;
		else if n_firstage_exact>=8 & n_firstage_exact<9 then n_firstage=8;
		else if n_firstage_exact>=9 & n_firstage_exact<10 then n_firstage=9;
		else if n_firstage_exact>=10 & n_firstage_exact<11 then n_firstage=10;
		else if n_firstage_exact>=11 & n_firstage_exact<12 then n_firstage=11;
		else if n_firstage_exact>=12 & n_firstage_exact<13 then n_firstage=12;
		else if n_firstage_exact>=13 & n_firstage_exact<14 then n_firstage=13;
		else if n_firstage_exact>=14 & n_firstage_exact<15 then n_firstage=14;
		else if n_firstage_exact>=15 & n_firstage_exact<16 then n_firstage=15;
		else if n_firstage_exact>=16 & n_firstage_exact<17 then n_firstage=16;
		else if n_firstage_exact>=17 & n_firstage_exact<18 then n_firstage=17;

* PREP FIRST STAGE VARIABLES;

	* Create on SSI variable for post years;
	array onssi(2004:2012) n_onssi_2004-n_onssi_2012;
	array pay(2004:2012) n_combpay_2004-n_combpay_2012;
	do i=2004 to 2012;
		if pay(i)>0 then onssi(i)=1; else onssi(i)=0;
	end;
	n_onssipost=sum(of n_onssi_2004-n_onssi_2012)/9;

	* Create average annual payment post-CDR;
	n_avgpay18=n_combpay18/min(18,2012-cdr_dobyy);

	* Create pre-treatment variables for falsification;
	n_paymonpre=sum(of n_paymon_1985-n_paymon_2003)/19;
	n_combpaypre=sum(of n_combpay_1985-n_combpay_2003)/19;

	* Create post-treatment variables;
	n_paymon_2yr=sum(of n_paymon_1985-n_paymon_2005);
	n_paymon_5yr=sum(of n_paymon_1985-n_paymon_2008);
	n_paymon_9yr=sum(of n_paymon_1985-n_paymon_2012);
	n_paymonpost=sum(of n_paymon_2004-n_paymon_2012)/8.5;
	n_paymoncum=sum(of n_paymon_2004-n_paymon_2012);

	n_combpay_2yr=sum(of n_combpay_1985-n_combpay_2005);
	n_combpay_5yr=sum(of n_combpay_1985-n_combpay_2008);
	n_combpay_9yr=sum(of n_combpay_1985-n_combpay_2012);
	n_combpaypost=sum(of n_combpay_2004-n_combpay_2012)/8.5;
	n_combpaycum=sum(of n_combpay_2004-n_combpay_2012);

* PREP OUTCOME VARIABLES (BENEFITS ONLY);
	n_hhdiamt0206=sum(of n_hhmbayr0206_2004-n_hhmbayr0206_2011)/8;
	n_hhssipay0206=sum(of n_hhcombpay0206_2004-n_hhcombpay0206_2012)/8.5;
	n_sibssipay=sum(of n_sibpayall_2004-n_sibpayall_2012)/8;
	n_sibnumssi=max(of n_sibnumon_2004-n_sibnumon_2012);

	n_hhappdi0206=sum(of n_par831di0206_2004-n_par831di0206_2011)/8;
	n_hhappssi0206=sum(of n_par831ssi0206_2004-n_par831ssi0206_2011)/8;
	n_kidappssi=sum(of n_kid831_ssi_2004-n_kid831_ssi_2011)/8;
	n_kidappdi=sum(of n_kid831_di_2004-n_kid831_di_2011)/8;
	n_sibappnum=sum(of n_sibappnum_2004-n_sibappnum_2012)/8;

	n_totapp0206=n_hhappdi0206+n_hhappssi0206+n_sibappnum;

	array hhunearninc0206(1985:2011) n_hhunearninc0206_1985-n_hhunearninc0206_2011;
	array hhunearnwokid0206(1985:2011) n_hhunearnwokid0206_1985-n_hhunearnwokid0206_2011;
	array hhmbayr0206(1985:2011) n_hhmbayr0206_1985-n_hhmbayr0206_2011;
	array combpay(1985:2011) n_combpay_1985-n_combpay_2011;
	array hhcombpay0206(1985:2011) n_hhcombpay0206_1985-n_hhcombpay0206_2011;
	array sibpayall(1985:2011) n_sibpayall_1985-n_sibpayall_2011;

	do i=1985 to 2011;
		hhunearninc0206(i)=hhmbayr0206(i)+combpay(i)+hhcombpay0206(i)+sibpayall(i);
	end;

	do i=1985 to 2011;
		hhunearnwokid0206(i)=hhmbayr0206(i)+hhcombpay0206(i)+sibpayall(i);
	end;

	n_hhunearn0206=sum(of n_hhunearninc0206_2004-n_hhunearninc0206_2011)/8;
	n_hhunearnwokid0206=sum(of n_hhunearnwokid0206_2004-n_hhunearnwokid0206_2011)/8;

* PARENT AND CHILD DEATH;

	* Convert births and deaths to date format;
	%macro date(var);
	&var._yr=substr(&var.,5,4);
	&var._mm=substr(&var.,1,2);
	&var._dd=substr(&var.,3,2);
	if &var._mm='XX' | &var._mm='00' then &var._mm='01';
	if &var._dd='XX' | &var._dd='00' then &var._dd='01';
	&var._sas=mdy(&var._mm, &var._dd, &var._yr);
	drop &var._yr &var._mm &var._dd;
	%mend date;

	%date(kiddod);
	%date(pardod1); %date(pardod2); %date(pardod3); %date(pardod4); %date(pardod5); 
	%date(pardod6); %date(pardod7);

	cdr_dob_str=put(cdr_dob,8.);
	cdr_dobmm=substr(cdr_dob_str,5,2);
	cdr_dobdd=substr(cdr_dob_str,7,2);
	cdr_dob_sas=mdy(cdr_dobmm, cdr_dobdd, cdr_dobyy);

	* Child's age at death;
	kiddeath_age=(kiddod_sas-cdr_dob_sas)/365;

	* Create parent and child death variables at X years out;
	if (pardeathtot0206>0 | kiddeath>0) then anydeath0206=1; else anydeath0206=0;

	if kiddeath>0 & substr(kiddod,5,4)<=2006 & substr(kiddod,5,4)>=2003 
		then kiddeath_1yr=1; else kiddeath_1yr=0;
	if kiddeath>0 & substr(kiddod,5,4)<=2010 & substr(kiddod,5,4)>=2003
		then kiddeath_5yr=1; else kiddeath_5yr=0;
	if kiddeath>0 & substr(kiddod,5,4)<=2013 & substr(kiddod,5,4)>2010
		then kiddeath_5topres=1; else kiddeath_5topres=0;

	if pardeathtot0206>0 & 
		(
			(substr(pardod1,5,4)<=2006 & substr(pardod1,5,4)>=2003) |
			(substr(pardod2,5,4)<=2006 & substr(pardod2,5,4)>=2003) |
			(substr(pardod3,5,4)<=2006 & substr(pardod3,5,4)>=2003) |
			(substr(pardod4,5,4)<=2006 & substr(pardod4,5,4)>=2003) |
			(substr(pardod5,5,4)<=2006 & substr(pardod5,5,4)>=2003) |
			(substr(pardod6,5,4)<=2006 & substr(pardod6,5,4)>=2003) |
			(substr(pardod7,5,4)<=2006 & substr(pardod7,5,4)>=2003)
		)
	then pardeath0206_1yr=1; else pardeath0206_1yr=0;

	if pardeathtot0206>0 & 
		(
			(substr(pardod1,5,4)<=2010 & substr(pardod1,5,4)>=2003) |
			(substr(pardod2,5,4)<=2010 & substr(pardod2,5,4)>=2003) |
			(substr(pardod3,5,4)<=2010 & substr(pardod3,5,4)>=2003) |
			(substr(pardod4,5,4)<=2010 & substr(pardod4,5,4)>=2003) |
			(substr(pardod5,5,4)<=2010 & substr(pardod5,5,4)>=2003) |
			(substr(pardod6,5,4)<=2010 & substr(pardod6,5,4)>=2003) |
			(substr(pardod7,5,4)<=2010 & substr(pardod7,5,4)>=2003)
		)
	then pardeath0206_5yr=1; else pardeath0206_5yr=0;

	if pardeathtot0206>0 & 
		(
			(substr(pardod1,5,4)<=2013 & substr(pardod1,5,4)>2010) |
			(substr(pardod2,5,4)<=2013 & substr(pardod2,5,4)>2010) |
			(substr(pardod3,5,4)<=2013 & substr(pardod3,5,4)>2010) |
			(substr(pardod4,5,4)<=2013 & substr(pardod4,5,4)>2010) |
			(substr(pardod5,5,4)<=2013 & substr(pardod5,5,4)>2010) |
			(substr(pardod6,5,4)<=2013 & substr(pardod6,5,4)>2010) |
			(substr(pardod7,5,4)<=2013 & substr(pardod7,5,4)>2010)
		)
	then pardeath0206_5topres=1; else pardeath0206_5topres=0;

	if (pardeath0206_1yr>0 | kiddeath_1yr>0) then anydeath0206_1yr=1; else anydeath0206_1yr=0;
	if (pardeath0206_5yr>0 | kiddeath_5yr>0) then anydeath0206_5yr=1; else anydeath0206_5yr=0;
	if (pardeath0206_5topres>0 | kiddeath_5topres>0) then anydeath0206_5topres=1; 
		else anydeath0206_5topres=0;


* PREP PRE-TREATMENT VARIABLES (CONTROLS);
	n_hhdiamt0206pre=sum(of n_hhmbayr0206_1992-n_hhmbayr0206_2003)/12;
	n_hhssipay0206pre=sum(of n_hhcombpay0206_1992-n_hhcombpay0206_2003)/12;
	n_sibssipaypre=sum(of n_sibpayall_1992-n_sibpayall_2003)/12;

	n_hhappdi0206pre=sum(of n_par831di0206_1992-n_par831di0206_2003)/12;
	n_hhappssi0206pre=sum(of n_par831ssi0206_1992-n_par831ssi0206_2003)/12;
	n_kidappssipre=sum(of n_kid831_ssi_1992-n_kid831_ssi_2003)/12;
	n_kidappdipre=sum(of n_kid831_di_1992-n_kid831_di_2003)/12;
	n_sibappnumpre=sum(of n_sibappnum_1992-n_sibappnum_2003)/12;

	n_totapp0206pre=n_hhappdi0206pre+n_hhappssi0206pre+n_sibappnumpre;

	n_hhunearn0206pre=sum(of n_hhunearninc0206_1992-n_hhunearninc0206_2003)/12;
	n_hhunearnwokid0206pre=sum(of n_hhunearnwokid0206_1992-n_hhunearnwokid0206_2003)/12;

* PREP TO MAKE SCATTER PLOT;

	* Create a Stata date variable for award date;
	awddte_str=put(awddte,8.);
	awddte_yr=substr(awddte_str,1,4);
	awddte_mm=substr(awddte_str,5,2);
	awddte_dd=substr(awddte_str,7,2);
	awddte_sas=mdy(awddte_mm, awddte_dd, awddte_yr);
	awddte_run=awddte_sas-mdy(10,01,2001);

	* Create dummies for FY2001 entry and FY2002 entry;
	if (awddte_sas<mdy(10,01,2001) & awddte_sas>=mdy(10,01,2000))
		then n_fy01ent=1;
		else n_fy01ent=0;
	if (awddte_sas<mdy(10,01,2002) & awddte_sas>=mdy(10,01,2001))
		then n_fy02ent=1;
		else n_fy02ent=0;
	
	* Create dummies for CY2001 entry and CY2002 entry;
	if (awddte_sas<mdy(01,01,2002) & awddte_sas>=mdy(01,01,2001))
		then n_cy01ent=1;
		else n_cy01ent=0;
	if (awddte_sas<mdy(01,01,2003) & awddte_sas>=mdy(01,01,2002))
		then n_cy02ent=1;
		else n_cy02ent=0;

run;

data manasi.analysis04_entryrd_stata;
	set manasi.analysis04_entryrd 
	(keep= hun fy_2004 fy_2005 fy cdr_mddate awddte cdr_imppri
	par1_dobyy_: par2_dobyy_: par1_sex_: par2_sex_: toa
	cdr_dds_date cdr_dds_det onset_dt
	awddte_run awddte_sas awddte_yr awddte_mm awddte_dd 
	n_fy01ent n_fy02ent 
	n_cdr_rel n_cdrunfav_18 n_paymon18 n_combpay18 n_avgpay18 
	
	n_onssipost
	n_paymonpre n_paymonpost n_paymoncum n_paymon_2yr n_paymon_5yr n_paymon_9yr n_paymonlife 
	n_combpaypre n_combpaypost n_combpaycum n_combpay_2yr n_combpay_5yr n_combpay_9yr n_combpaylife

	n_hhdiamt0206 n_hhssipay0206 n_sibssipay n_sibnumssi
	n_hhappdi0206 n_hhappssi0206 n_sibappnum n_totapp0206
	n_kidappdi n_kidappssi 
	n_hhunearn0206 n_hhunearnwokid0206

	pardeathtot0206 kiddeath anydeath0206 kiddeath_age
	pardeath0206_1yr pardeath0206_5yr pardeath0206_5topres
	kiddeath_1yr kiddeath_5yr kiddeath_5topres
	anydeath0206_1yr anydeath0206_5yr anydeath0206_5topres

	n_totapp0206pre n_hhunearnwokid0206pre

	cdr_dob cdr_dobyy cdr_dobmm cdr_dobdd cdr_dob_sas
	cdr_bodysys n_male n_firstage n_firstpayyr cdr_state
	n_dibmdrcat n_diag1cat
	kiddod pardod:
	
	n_hhunearninc0206_: n_hhunearnwokid0206_:
	n_combpay_:  n_paymon_:

	);

	* Keep only the award dates in FY2001 and FY2002, kids on 3 year cycle;
	if (awddte_run<300 & awddte_run>-300) & n_dibmdrcat=3;

run;


* PREP DATA FOR DD ;
data manasi.analysis_cdrdrop040506;
	set manasi.kids_cdryrs_mergecdr_clean
		manasi.kids_cdryrs0607_mergecdr_clean;
run;

data manasi.analysis_cdrdrop040506;
	set manasi.analysis_cdrdrop040506 (rename=(n_firstage=n_firstage_exact));
	
* KEEP ONLY FY2004/FY2005/06 KIDS WHO ARE NOT ON HOLD;
	if (fy=2004 | fy=2005| fy=2006) & n_cdr_hold=0;
	drop cs_toa mft n_diag2_: ;

* Identify missing FYs;
	if fy='2004' & fy_2004=. then fy_2004=1 ;
	if fy='2004' & fy_2005=. then fy_2005=0 ;
	if fy='2005' & fy_2004=. then fy_2004=0 ;
	if fy='2005' & fy_2005=. then fy_2005=1 ;

	if fy='2005' & fy_2005=. then fy_2005=1 ;
	if fy='2005' & fy_2006=. then fy_2006=0 ;
	if fy='2006' & fy_2005=. then fy_2005=0 ;
	if fy='2006' & fy_2006=. then fy_2006=1 ;

* Create one categorical variable for diagnosis;
	if n_diag1_infec=1 			then n_diag1cat=1 ;
	else if n_diag1_neo=1 		then n_diag1cat=2 ;
	else if n_diag1_endo=1		then n_diag1cat=3 ;
	else if n_diag1_blood=1		then n_diag1cat=4 ;
	else if n_diag1_mental=1	then n_diag1cat=5 ;
	else if n_diag1_nerv=1		then n_diag1cat=6 ;
	else if n_diag1_sense=1		then n_diag1cat=7 ;
	else if n_diag1_circ=1		then n_diag1cat=8 ;
	else if n_diag1_resp=1		then n_diag1cat=9 ;
	else if n_diag1_dig=1		then n_diag1cat=10 ;
	else if n_diag1_gu=1		then n_diag1cat=11 ;
	else if n_diag1_preg=1		then n_diag1cat=12 ;
	else if n_diag1_skin=1		then n_diag1cat=13 ;
	else if n_diag1_musc=1		then n_diag1cat=14 ;
	else if n_diag1_cong=1		then n_diag1cat=15 ;
	else if n_diag1_nat=1		then n_diag1cat=16 ;
	else if n_diag1_ill=1		then n_diag1cat=17 ;
	else if n_diag1_inj=1		then n_diag1cat=18 ;

* RENAME FIRST AGE VARIABLE;
	if n_firstage_exact>=0 & n_firstage_exact<1 then n_firstage=0;
		else if n_firstage_exact>=1 & n_firstage_exact<2 then n_firstage=1;
		else if n_firstage_exact>=2 & n_firstage_exact<3 then n_firstage=2;
		else if n_firstage_exact>=3 & n_firstage_exact<4 then n_firstage=3;
		else if n_firstage_exact>=4 & n_firstage_exact<5 then n_firstage=4;
		else if n_firstage_exact>=5 & n_firstage_exact<6 then n_firstage=5;
		else if n_firstage_exact>=6 & n_firstage_exact<7 then n_firstage=6;
		else if n_firstage_exact>=7 & n_firstage_exact<8 then n_firstage=7;
		else if n_firstage_exact>=8 & n_firstage_exact<9 then n_firstage=8;
		else if n_firstage_exact>=9 & n_firstage_exact<10 then n_firstage=9;
		else if n_firstage_exact>=10 & n_firstage_exact<11 then n_firstage=10;
		else if n_firstage_exact>=11 & n_firstage_exact<12 then n_firstage=11;
		else if n_firstage_exact>=12 & n_firstage_exact<13 then n_firstage=12;
		else if n_firstage_exact>=13 & n_firstage_exact<14 then n_firstage=13;
		else if n_firstage_exact>=14 & n_firstage_exact<15 then n_firstage=14;
		else if n_firstage_exact>=15 & n_firstage_exact<16 then n_firstage=15;
		else if n_firstage_exact>=16 & n_firstage_exact<17 then n_firstage=16;
		else if n_firstage_exact>=17 & n_firstage_exact<18 then n_firstage=17;

* PREP OUTCOME VARIABLES (BENEFITS ONLY);
	array hhunearninc0206(1985:2011) n_hhunearninc0206_1985-n_hhunearninc0206_2011;
	array hhunearnwokid0206(1985:2011) n_hhunearnwokid0206_1985-n_hhunearnwokid0206_2011;
	array hhmbayr0206(1985:2011) n_hhmbayr0206_1985-n_hhmbayr0206_2011;
	array combpay(1985:2011) n_combpay_1985-n_combpay_2011;
	array hhcombpay0206(1985:2011) n_hhcombpay0206_1985-n_hhcombpay0206_2011;
	array sibpayall(1985:2011) n_sibpayall_1985-n_sibpayall_2011;
	array hhappdi0206(1985:2011) n_par831di0206_1985-n_par831di0206_2011;
	array hhappssi0206(1985:2011) n_par831ssi0206_1985-n_par831ssi0206_2011;
	array sibappnum(1985:2011) n_sibappnum_1985-n_sibappnum_2011;
	array totapp0206(1985:2011) n_totapp0206_1985-n_totapp0206_2011;

	do i=1985 to 2011;
		hhunearninc0206(i)=hhmbayr0206(i)+combpay(i)+hhcombpay0206(i)+sibpayall(i);
	end;

	do i=1985 to 2011;
		hhunearnwokid0206(i)=hhmbayr0206(i)+hhcombpay0206(i)+sibpayall(i);
	end;

	do i=1985 to 2011;
		totapp0206(i)=hhappdi0206(i)+hhappssi0206(i)+sibappnum(i);
	end;

	if (pardeathtot0206>0 | kiddeath>0) then anydeath0206=1; else anydeath0206=0;

%macro var(year,yrplus,yrminus1,yrminus2,yrminus3,yrminus4,yrminus5,yrminus6,yrminus7,yrminus8,yrminus9,yrminus10,yrminus11,yrminus12);
if fy=&year. then 
	do;

	n_paymonpost=sum(of n_paymon_&year.-n_paymon_2012)/(2011.5-&yrminus1.);
	n_combpaypost=sum(of n_combpay_&year.-n_combpay_2012)/(2011.5-&yrminus1.);

	n_hhdiamt0206=sum(of n_hhmbayr0206_&year.-n_hhmbayr0206_2011)/(2011-&yrminus1.);
	n_hhssipay0206=sum(of n_hhcombpay0206_&year.-n_hhcombpay0206_2012)/(2011.5-&yrminus1.);
	n_sibssipay=sum(of n_sibpayall_&year.-n_sibpayall_2012)/(2011-&yrminus1.);

	n_hhappdi0206=sum(of n_par831di0206_&year.-n_par831di0206_2011)/(2011-&yrminus1.);
	n_hhappssi0206=sum(of n_par831ssi0206_&year.-n_par831ssi0206_2011)/(2011-&yrminus1.);
	n_kidappssi=sum(of n_kid831_ssi_&year.-n_kid831_ssi_2011)/(2011-&yrminus1.);
	n_sibappnum=sum(of n_sibappnum_&year.-n_sibappnum_2012)/(2011-&yrminus1.);

	n_hhunearn0206=sum(of n_hhunearninc0206_&year.-n_hhunearninc0206_2011)/(2011-&yrminus1.);
	n_hhunearnwokid0206=sum(of n_hhunearnwokid0206_&year.-n_hhunearnwokid0206_2011)/(2011-&yrminus1.);

* PREP PRE-TREATMENT VARIABLES FOR EACH PRE-TREATMENT YEAR (CONTROLS);
	n_combpaypre_1=		n_combpay_&yrminus1.;
	n_combpaypre_2=		n_combpay_&yrminus2.;
	n_combpaypre_3=		n_combpay_&yrminus3.;
	n_combpaypre_4=		n_combpay_&yrminus4.;
	n_combpaypre_5=		n_combpay_&yrminus5.;
	n_combpaypre_6=		n_combpay_&yrminus6.;
	n_combpaypre_7=		n_combpay_&yrminus7.;
	n_combpaypre_8=		n_combpay_&yrminus8.;
	n_combpaypre_9=		n_combpay_&yrminus9.;
	n_combpaypre_10=	n_combpay_&yrminus10.;
	n_combpaypre_11=	n_combpay_&yrminus11.;
	n_combpaypre_12=	n_combpay_&yrminus12.;

	n_totapp0206pre_1=	n_totapp0206_&yrminus1.;
	n_totapp0206pre_2=	n_totapp0206_&yrminus2.;
	n_totapp0206pre_3=	n_totapp0206_&yrminus3.;
	n_totapp0206pre_4=	n_totapp0206_&yrminus4.;
	n_totapp0206pre_5=	n_totapp0206_&yrminus5.;
	n_totapp0206pre_6=	n_totapp0206_&yrminus6.;
	n_totapp0206pre_7=	n_totapp0206_&yrminus7.;
	n_totapp0206pre_8=	n_totapp0206_&yrminus8.;
	n_totapp0206pre_9=	n_totapp0206_&yrminus9.;
	n_totapp0206pre_10=	n_totapp0206_&yrminus10.;
	n_totapp0206pre_11=	n_totapp0206_&yrminus11.;
	n_totapp0206pre_12=	n_totapp0206_&yrminus12.;

	n_hhunearninc0206pre_1=		n_hhunearninc0206_&yrminus1.;
	n_hhunearninc0206pre_2=		n_hhunearninc0206_&yrminus2.;
	n_hhunearninc0206pre_3=		n_hhunearninc0206_&yrminus3.;
	n_hhunearninc0206pre_4=		n_hhunearninc0206_&yrminus4.;
	n_hhunearninc0206pre_5=		n_hhunearninc0206_&yrminus5.;
	n_hhunearninc0206pre_6=		n_hhunearninc0206_&yrminus6.;
	n_hhunearninc0206pre_7=		n_hhunearninc0206_&yrminus7.;
	n_hhunearninc0206pre_8=		n_hhunearninc0206_&yrminus8.;
	n_hhunearninc0206pre_9=		n_hhunearninc0206_&yrminus9.;
	n_hhunearninc0206pre_10=	n_hhunearninc0206_&yrminus10.;
	n_hhunearninc0206pre_11=	n_hhunearninc0206_&yrminus11.;
	n_hhunearninc0206pre_12=	n_hhunearninc0206_&yrminus12.;

	n_hhunearnwokid0206pre_1=	n_hhunearnwokid0206_&yrminus1.;
	n_hhunearnwokid0206pre_2=	n_hhunearnwokid0206_&yrminus2.;
	n_hhunearnwokid0206pre_3=	n_hhunearnwokid0206_&yrminus3.;
	n_hhunearnwokid0206pre_4=	n_hhunearnwokid0206_&yrminus4.;
	n_hhunearnwokid0206pre_5=	n_hhunearnwokid0206_&yrminus5.;
	n_hhunearnwokid0206pre_6=	n_hhunearnwokid0206_&yrminus6.;
	n_hhunearnwokid0206pre_7=	n_hhunearnwokid0206_&yrminus7.;
	n_hhunearnwokid0206pre_8=	n_hhunearnwokid0206_&yrminus8.;
	n_hhunearnwokid0206pre_9=	n_hhunearnwokid0206_&yrminus9.;
	n_hhunearnwokid0206pre_10=	n_hhunearnwokid0206_&yrminus10.;
	n_hhunearnwokid0206pre_11=	n_hhunearnwokid0206_&yrminus11.;
	n_hhunearnwokid0206pre_12=	n_hhunearnwokid0206_&yrminus12.;

	end;

%mend var;

	%var(2004,2005,2003,2002,2001,2000,1999,1998,1997,1996,1995,1994,1993,1992);
	%var(2005,2006,2004,2003,2002,2001,2000,1999,1998,1997,1996,1995,1994,1993);
	%var(2006,2007,2005,2004,2003,2002,2001,2000,1999,1998,1997,1996,1995,1994);

	n_totapp0206=n_hhappdi0206+n_hhappssi0206+n_sibappnum;

* PREP PRE-TREATMENT VARIABLES (for complier characteristics);

	n_paymonpre=sum(of n_paymon_1992-n_paymon_2002)/11;
	n_combpaypre=sum(of n_combpay_1992-n_combpay_2002)/11;

	n_hhdiamt0206pre=sum(of n_hhmbayr0206_1992-n_hhmbayr0206_2002)/11;
	n_hhssipay0206pre=sum(of n_hhcombpay0206_1992-n_hhcombpay0206_2002)/11;
	n_sibssipaypre=sum(of n_sibpayall_1992-n_sibpayall_2002)/11;

	n_hhappdi0206pre=sum(of n_par831di0206_1992-n_par831di0206_2002)/11;
	n_hhappssi0206pre=sum(of n_par831ssi0206_1992-n_par831ssi0206_2002)/11;
	n_kidappssipre=sum(of n_kid831_ssi_1992-n_kid831_ssi_2002)/11;
	n_sibappnumpre=sum(of n_sibappnum_1992-n_sibappnum_2002)/11;

	n_totapp0206pre=n_hhappdi0206pre+n_hhappssi0206pre+n_sibappnumpre;

	n_hhunearn0206pre=sum(of n_hhunearninc0206_1992-n_hhunearninc0206_2002)/11;
	n_hhunearnwokid0206pre=sum(of n_hhunearnwokid0206_1992-n_hhunearnwokid0206_2002)/11;

	* Create a Stata date variable for award date;
	awddte_str=put(awddte,8.);
	awddte_yr=substr(awddte_str,1,4);
	awddte_mm=substr(awddte_str,5,2);
	awddte_dd=substr(awddte_str,7,2);
	awddte_sas=mdy(awddte_mm, awddte_dd, awddte_yr);
	awddte_run=awddte_sas-mdy(10,01,2001);

run;

data manasi.analysis_cdrdrop040506_stata;
	set manasi.analysis_cdrdrop040506 
	(keep= fy_2004 fy_2005 fy_2006 fy cdr_mddate awddte cdr_imppri 
	n_cdr_rel n_eligssn
	par1_dobyy_: par2_dobyy_: par1_sex_: par2_sex_: toa
	n_paymon_1985-n_paymon_2012 
	n_combpay_1985-n_combpay_2012 
	n_hhmbayr0206_1985-n_hhmbayr0206_2011
	n_hhcombpay0206_1985-n_hhcombpay0206_2012
	n_sibpayall_1985-n_sibpayall_2012
	n_sibappnum_:
	n_par831di0206_1985-n_par831di0206_2011
	n_par831ssi0206_1985-n_par831ssi0206_2011
	n_kid831_di_1985-n_kid831_di_2011
	n_kid831_ssi_1985-n_kid831_ssi_2011
	n_totapp0206_1985-n_totapp0206_2011
	n_hhunearninc0206_1985-n_hhunearninc0206_2011
	n_hhunearnwokid0206_1985-n_hhunearnwokid0206_2011
	cdr_reldate cdr_dds_date cdr_dds_det
	hun cdr_bodysys n_male cdr_dobyy n_firstage n_firstpayyr cdr_state
	n_dibmdrcat n_diag1cat);

	* Keep only those with MDD in FY04 or FY05 or FY06;
    if cdr_mddate>=200310;
run;
